package com.gitbl.webchat.db.mapper;

import com.gitbl.webchat.db.bean.UserBean;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface UserMapper {
    @Select("select count(0) from user where username=#{username}")
    boolean exist(String username);

    @Select("select * from user where username=#{username} and pwd=#{pwd}")
    @ResultMap(value = "userMap")
    UserBean login(@Param("username") String username,@Param("pwd") String pwd);


    @Select("select * from user")
    @Results(id="userMap",value={
            @Result(column="username", property="userName", jdbcType= JdbcType.VARCHAR, id=true),
            @Result(column="pwd", property="pwd", jdbcType=JdbcType.VARCHAR),
            @Result(column="nickname", property="nickName", jdbcType=JdbcType.VARCHAR)
    }
    )
    List<UserBean> getAllUser();

    @Insert("insert into user (username,nickname,pwd) values(#{userName},#{nickName},#{pwd})")
    boolean signup(UserBean userBean) throws Exception;
}
